package 
{
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	import flash.text.*;
	
	
	/**
	 * ...
	 * @author Minfang
	 */
	
	
	public class Main extends Sprite 
	{
		private var bkColor:Sprite;
		private var scroll_table:ScrollTable;
		public var default_background_color:uint = 0xeeeeee;
		public function Main():void 
		{
			
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
			
			
			
			
			
		}
		
		
		
		private function init(e:Event = null):void 
		{
			//ExternalInterface.call('changeSize', '400px','300px');
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			stage.scaleMode = "noScale";
			stage.align = "TL";
			
						
			bkColor = new Sprite;
			
	
			bkColor.graphics.beginFill(default_background_color);	
			bkColor.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
			bkColor.graphics.endFill();
			
			x = 0;
			y = 0;
			
			addChild(bkColor);
			var reStr:String = "";
			if(ExternalInterface.available){
			
				ExternalInterface.marshallExceptions = true;
				 try {
					ExternalInterface.addCallback('setupScrollTableBackgroupColor', setBackGroundColor);
				} catch(e:Error) {
					trace(e)
				}
				
				
				
				var paramObj:Object =  LoaderInfo(this.root.loaderInfo).parameters;   //set the paramObj variable to the parameters property of the LoaderInfo object
				
				var globalCss:String = null;
				
				try{
					globalCss=ExternalInterface.call("loadDataForScrollTable", 'css');
				}
				catch(e:Error) {
					trace(e)
				}
				
				if (paramObj['id'] != undefined) {
					var id:String = paramObj['id'];
					try{
						reStr = ExternalInterface.call("loadDataForScrollTable", id);
					}
					catch(e:Error) {
						trace(e)
					}
					if (reStr != null ) {
						
						
						scroll_table = new ScrollTable(stage, reStr, globalCss);
						scroll_table.x += scroll_table.stage_padding_left;
						scroll_table.y += scroll_table.stage_padding_top;
						addChild(scroll_table);
						
						try{
							ExternalInterface.call("resetStageHeight", id,scroll_table.new_stage_height);
						}
						catch(e:Error) {
							trace(e)
						}
					}
				}
			}
			else {
				
				reStr = "{\"locked_top\":{\"data\":[[\"< $10K\",\"$10K - $19.9K\",\"$20K - $29.9K\",\"$30K - $39.9K\",\"$40K - $49.9K\",\"$50K - $59.9K\",\"$60K - $69.9K\",\"$70K - $79.9K\",\"$80K - $89.9K\",\"$90K - $99.9K\",\"$100K - $149.9K\",\"$150K - $174.9K\",\"$175K - $199.9K\",\"$200K - $249.9K\",\"$250K+\"]],\"line_setting\":{\"top_line\":1,\"inter_column_line\":1,\"inter_row_line\":1,\"0\":\"left_line=>1\"},\"class\":\"top_class\",\"background_color\":15658734},\"locked_bottom\":{\"data\":[[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"]],\"line_setting\":{\"bottom_line\":1},\"class\":\"bottom_class\",\"background_color\":14145493},\"locked_left\":{\"data\":[[\"2012-01-18\"],[\"2012-01-19\"],[\"2012-01-20\"],[\"2012-01-21\"],[\"2012-01-22\"],[\"2012-01-23\"],[\"2012-01-24\"],[\"2012-01-25\"],[\"2012-01-26\"],[\"2012-01-27\"],[\"2012-01-28\"],[\"2012-01-29\"],[\"2012-01-30\"],[\"2012-01-31\"],[\"2012-02-01\"],[\"2012-02-02\"],[\"2012-02-03\"],[\"2012-02-04\"],[\"2012-02-05\"],[\"2012-02-06\"],[\"2012-02-07\"],[\"2012-02-08\"],[\"2012-02-09\"],[\"2012-02-10\"],[\"2012-02-11\"],[\"2012-02-12\"],[\"2012-02-13\"],[\"2012-02-14\"],[\"2012-02-15\"],[\"2012-02-16\"],[\"2012-02-17\"],[\"2012-02-18\"],[\"2012-02-19\"]],\"line_setting\":{\"inter_row_line\":1,\"line_style_bmp\":[[8947848],[16777215]]},\"class\":\"left_class\",\"background_color\":14803425},\"locked_tl\":{\"data\":[[\"Date\"]],\"line_setting\":{\"top_line\":1},\"class\":\"tl_class\",\"background_color\":15658734},\"locked_bl\":{\"data\":[[\"Cumulative\"]],\"line_setting\":{\"bottom_line\":1},\"class\":\"bl_class\",\"background_color\":14145493},\"body\":{\"data\":[[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"],[\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\",\"0.00%\"]],\"line_setting\":{\"inter_row_line\":1,\"line_style_bmp\":[[8947848],[16777215]]},\"class\":\"body_class\",\"background_color\":15198181}}";
				var css:String = ".top_class , .left_class, .tl_class, .bottom_class, .bl_class{\n\tfont-weight: bold;\n\t\n}\n\np{\n\ttext-align: center;\n}\n\n\n\n";
				scroll_table = new ScrollTable(stage, reStr,css);
				addChild(scroll_table);
			}

		}
		
		public function setBackGroundColor(col:uint):void {
			bkColor.graphics.beginFill(col);	
			bkColor.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
			bkColor.graphics.endFill();
		}
		
	}
	
}